//app.js
import {request} from '/request/index.js'
import regeneratorRuntime from '/lib/runtime/runtime';
App({
  onLaunch: function () {
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        if (res.code) {
          // console.log("code========" + JSON.stringify(res));
          console.log(res.code)
          //发起网络请求
          let that = this
          wx.request({
            //  url: 'https://api.weixin.qq.com/sns/jscode2session?appid=wx156cc69fadc9380b&secret=bd204e94b46b5982be140a4ce8a63dd9&grant_type=authorization_code&js_code='+res.code,
            url: 'https://www.heilama.com:8383/other/sessionKey',
            data:{
              code:res.code
            },
            method: "post",
            // header: { 'content-type': 'application/json;charset=UTF-8' },
            success: res =>{
              console.log(res)
              that.globalData.openid = res.data.data.openid;
              that.globalData.session_key=res.data.data.session_key;
              console.log(that.globalData.openid);
            },
            fail:function(err){
              console.log(err)
            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
  },
  // globalData: {
  //   appid: 'wxf50319d5115b2f2e',  
  //   secret: 'd4de19e5e58a6793d23db39b48d7d632',
  //   openid:null, 
  //   session_key: null,
  // }

  // 企业号
  globalData: {
    appid: 'wx156cc69fadc9380b',  
    secret: 'bd204e94b46b5982be140a4ce8a63dd9',
    openid:null, 
    session_key: null,
  }
})